#pragma once
#include "DXContext.h"
#include <map>
#include "NativePointer.h"
#include "enums.h"

namespace DXBase
{
	namespace D3D
	{
		interface class IResource;

		public ref class NativeResource sealed
		{
		internal:
			NativeResource(Microsoft::WRL::ComPtr<ID3D11Resource> res) : resource(res) {}
			Microsoft::WRL::ComPtr<ID3D11Resource> resource;
		};

		public ref class NativeShaderResourceView sealed
		{
		internal:
			NativeShaderResourceView(Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> res) : resView(res) {};
			Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> resView;
		};

		[Windows::Foundation::Metadata::WebHostHidden]
		public ref class MappedSubresource sealed
		{
		private:
			IResource^ resource;
			MemoryBlock^ pData;
			UINT rowPitch;
			UINT depthPitch;
			uint32 subresource;

		internal:
			MappedSubresource(IResource^ res, uint32 subresource, D3D11_MAPPED_SUBRESOURCE& data);
		public:
			virtual ~MappedSubresource() { Unmap(); }
			void Unmap();

			property uint32 Subresource  { uint32 get() { return subresource; } }
			property UINT RowPitch   { UINT get() { return rowPitch; } }
			property UINT DepthPitch { UINT get() { return depthPitch; } }
			property MemoryBlock^ Data { MemoryBlock^ get() { return pData; } }
		};

		[Windows::Foundation::Metadata::WebHostHidden]
		public interface class IResource : IContextBound
		{
			MappedSubresource^ Map(uint32 subresource, D3D::Map mapType, MapFlag flag);
			void CopyTo(IResource^ other);
			// internals
			NativeShaderResourceView^ GetNativeShaderResourceView();
			NativeResource^ GetNativeResource();
		};

		MappedSubresource^ Resource_Map(IResource^ resource, uint32 subresource, D3D::Map mapType, MapFlag flag);
		void Resource_CopyTo(IResource^ src, IResource^ dst);
	}
}